import java.util.Arrays;

public class LeetCode260 {
    public static void main(String[] args) {
        //只出现一次的数字
        //https://leetcode.cn/problems/single-number-iii/solutions/587516/zhi-chu-xian-yi-ci-de-shu-zi-iii-by-leet-4i8e/

        Solution260 solution = new Solution260();
        int[] nums = new int[]{1,2,1,3,2,5};
        System.out.println(Arrays.toString(solution.singleNumber(nums)));
    }
}

class Solution260 {
    public int[] singleNumber(int[] nums) {
        //
        int arr = 0;
        for(int n : nums){
            arr = arr ^ n;
        }

        //防止溢出（这里不太明白）

        int flg = arr & (-arr);
        int type1 = 0;
        int type2 = 0;
        for(int n : nums){
            if((n & flg) == 0){
                type1 = type1 ^ n;
            }else{
                type2 = type2 ^ n;
            }
        }
        return new int[]{type1, type2};

    }
}
